Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Improvements in the reader from openPMD file #158

Merged
merged 23 commits into from
Aug 14, 2023

Conversation

MaxThevenet
Copy link
Contributor

@MaxThevenet MaxThevenet commented Aug 3, 2023

This PR proposes the following improvements, all meant to achieve #127:

  • The option to output the normalized vector potential instead of the electric field is implemented. For the rationale, see Improvements of the laser envelope extension openPMD/openPMD-standard#281. This is certainly open for discussion. Converters from E to a0 and reverse are implemented in utils (it is a very vanilla version, definitely room for improvement there).
  • The calculation of local and average frequency is in a separate function. This way, we can implement different methods to do this operation (e.g. FFT-based) easily.
  • profile from_array and from_openPMD now also support RZ representation. Without this, operating on the 3D data was not practical. Again, very vanilla implementation, the implementation assumes axial symmetry for the envelope, the mode decomposition is not included in this PR.

With these changes, the output of an FBPIC simulation can be sent as the input of a HiPACE++ simulation. The figure below shows, for a laser pulse in a parabolic channel, the pulse width during propagation, when starting the HiPACE++ simulation from the output of the FBPIC simulation at different times. Significant differences can be observed, which could very much come from differences between the two codes: even without using LASY the two codes give slightly different results for this case. This is probably a matter of tuning the resolution, box size, time step etc., so I do not think it is necessarily a problem.
laser_width_hipace_fbpic
laser_width_hipace_fbpic.pdf

The scripts I used are posted below, so we can later work on the agreement. I had to add some .txt to upload the files.

inputs_fbpic.py.txt
inputs_hipace.txt
script_fbpic.sh.txt
script_hipace.sh.txt

The lasy handling was done using:

from lasy.profiles.from_openpmd_profile import FromOpenPMDProfile
from lasy.laser import Laser
import matplotlib.pyplot as plt
from openpmd_viewer.addons import LpaDiagnostics
import scipy.constants as scc

profile2 = FromOpenPMDProfile('./DATA', 26, (0,1), 'E', 'y', theta=0)

dim = 'xyt'
lo = (-100e-6, -100e-6, 0)
hi = (+100e-6, +100e-6, (m0.zmax-m0.zmin)/scc.c)
npoints=(128, 128, 500)
## Tested, also works with
# dim = 'rt'
# lo = (0, 0)
# hi = (+100e-6, (m0.zmax-m0.zmin)/scc.c)
# npoints=(300, 600)
laser = Laser(dim, lo, hi, npoints, profile2)
laser.write_to_file('./lasy_t3/laser3d', use_a0=True)

@MaxThevenet MaxThevenet added new feature request or implementation of a new feature standard discussions on API and output standard labels Aug 3, 2023
@MaxThevenet MaxThevenet changed the title [WIP] Improvements in the reader from openPMD file Improvements in the reader from openPMD file Aug 4, 2023
@MaxThevenet
Copy link
Contributor Author

Tests pass, this is ready for review :)

@AngelFP
Copy link
Member

AngelFP commented Aug 10, 2023

Results from a similar test restarting an FBPIC simulation with Wake-T. Looking promising so far!

image

@MaxThevenet
Copy link
Contributor Author

MaxThevenet commented Aug 10, 2023

Thanks @AngelFP. The laser propagation is quite well-captured. Final iteration below. Unfortunately, the agreement still isn't great, but nothing that can obviously be attributed to LASY, probably some convergence question.
fig

Comment on lines 81 to +82
ts = OpenPMDTimeSeries(path)
F, m = ts.get_field(iteration=iteration, field=field, coord=coord, theta=None)
assert m.axes in [
{0: "x", 1: "y", 2: "z"},
{0: "z", 1: "y", 2: "x"},
{0: "x", 1: "y", 2: "t"},
{0: "t", 1: "y", 2: "x"},
]

if m.axes in [{0: "z", 1: "y", 2: "x"}, {0: "t", 1: "y", 2: "x"}]:
F = F.swapaxes(0, 2)

if "z" in m.axes.values():
t = (m.z - m.z[0]) / c
else:
t = m.t
axes = {"x": m.x, "y": m.y, "t": t}

# If array does not contain the envelope but the electric field,
# extract the envelope with a Hilbert transform
if envelope == False:
# Assumes z is last dimension!
h = hilbert(F)
F, m = ts.get_field(iteration=iteration, field=field, coord=coord, theta=theta)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In principle, we could avoid depending on the viewer here, but that would take a bit more work (in particular to properly convert from RZ decomposition of fields to RZ decomposition of envelope). I would be happy to discuss this.

@MaxThevenet
Copy link
Contributor Author

Thanks @AngelFP for your review, I addressed your comments in the last commits.

@AngelFP
Copy link
Member

AngelFP commented Aug 11, 2023

Great, thanks!

@MaxThevenet MaxThevenet merged commit ce55e2d into LASY-org:development Aug 14, 2023
@MaxThevenet MaxThevenet deleted the manip_utils branch August 14, 2023 07:24
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
new feature request or implementation of a new feature standard discussions on API and output standard
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants